import requests
import json

if __name__ == '__main__':
    # 请求头
    headers = {
        'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
    }
    url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname'
    response = ''
    for i in range(12):
        params = {
            'cname': '成都',
            'pageIndex': i,
            'pageSize': 10
        }
        response = response + (requests.post(url=url, params=params, headers=headers).text)
        print(response)
    res_json = json.loads(response)
    with open('kfc.json', 'w', encoding='utf-8') as fp:
        json.dump(res_json, fp=fp, ensure_ascii=False)
        fp.write(response)
    print('over!!!')
